package com.ucar.train.service.wufuqiang;

import com.ucar.train.utils.SpringUtils;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

/**
 * @author wufuqiang
 * @title: GeneRespChain
 * @projectName:train-parent
 * @description: 保养流程生成责任链
 * @created 2019-08-22 13:20
 */
@Component
public class GeneRespChainUtils {

    /**
     * @Author: wufuqiang
     * @Description: 根据要求自动生成责任链
     * @Param:a
     * @return:a
     * @Date: 2019/8/22
     */
    public static List<Handle> geneRespChain(String[] strs){

        List<Handle> chain = new ArrayList<>();
        for (String str:strs) {
            Handle handle = SpringUtils.getBean(str);
            chain.add(handle);
        }
        for (int i = 0;i < chain.size();i++){
            if(i != chain.size() - 1){
                chain.get(i).setNextHandle(chain.get(i+1));
            }
        }

//        Handle oil = new Oil();
//        Handle tire = new Tire();
//        Handle engine = new Engine();
//        Handle gearbox = new Gearbox();
//
//        oil.setNextHandle(tire);
//        tire.setNextHandle(engine);
//        engine.setNextHandle(gearbox);
//
//        List<Handle> chain = new ArrayList<>();
//        chain.add(oil);
//        chain.add(tire);
//        chain.add(engine);
//        chain.add(gearbox);
        return chain;
    }
}
